; (function (window) {
    if (window.tools || window.t) {
        throw new Error('已存在tools')
    }
    // 函数入口
    window.t = window.tools = function (selector) {
        return new tools.fn.init(selector)
    }
    // 工具函数
    tools.fn = tools.prototype = {

        version: 1,

        init: function (selector) {
            return this
        },

        // 防抖
        debounce: function (fn, wait) {
            let timer = null
            return function () {
                var arg = arguments
                if (timer) clearTimeout(timer)
                timer = setTimeout(function () {
                    fn.apply(fn, arg)
                }, wait)
            }
        },

        // 节流
        throttle: function (fn, wait) {
            var prevTime = 0
            return function () {
                var nowDate = Date.now()
                // 判断此时的时间是否已经超过了上次的执行时间
                if (nowDate - prevTime > wait) {
                    // 执行函数体
                    fn.apply(this, arguments)
                    // 赋值下次时间
                    prevTime = nowDate
                }
            }
        }
    }
    // 赋值prototype
    tools.fn.init.prototype = tools.prototype
})(window)
